<?php
namespace app\pet\controller;
use think\Db;

Class Banner extends Common{

    public function index(){
        $res = Db::name('banner')->where('is_delete',0)->select();
        $data = [];
        foreach ($res as $k=>$v){
            $callback = Db::connect('db_log')->name('upload_log')
            ->where('url',$v['img_url'])->find();
            array_push($data,$callback);
        }
        $this->assign('data',$res);
        $this->assign('img',$data);
        return $this->fetch();
    }

    public function txtSub(){
        $params = $this->params;
        $banner = $params['banner'];
        $banner = explode(',',$banner);
        Db::name('banner')->where('is_delete',0)->update(['is_delete'=>1]);
        foreach ($banner as $k=>$v){
            Db::name('banner')->where('id',$k+1)
            ->update(['img_url'=>$v,'href'=>$params['href'.($k+1)],
            'is_delete'=>0]);
        }
        return_msg(1,'上传成功！','#');
    }

}